﻿CREATE PROCEDURE [dbo].[proc_Project_GetItem]
	(
		@ProjectId uniqueidentifier
	)
AS
Select
	p.Id,
	p.ProjectId,
	p.OrderId,
	p.CusName,
	(Select GenJinKfAccount From [Order] Where OId=p.OrderId) As SalesmanAccount,		--跟单客服账号
	(Select GenJinKfName From [Order] Where OId=p.OrderId) As ProductCategoryName,	--跟单客服姓名
	(Select GenJinKfDepId From [Order] Where OId=p.OrderId) As ProductCategoryId,		--跟单客服部门ID
	p.ProductId,
	p.ProductName,
	p.SupplierId,
	p.SupplierName,
	p.CostPrice,
	p.SalePrice,
	p.Description,
	p.TypeId,
	p.TypeName,
	p.IsFinish,
	p.CompanyId,
	IsNull((Select CompanyName From [Company] Where [Company].id = p.CompanyId),'...') As CompanyName,
	p.Salesman,
	p.CreateUser,
	p.CreateDate,
	IsNull((Select EName From Employee Where UserName=p.CreateUser),'...') As CreateUserEName,
	IsNull(p.FinishDate,'1910/01/01') as FinishDate,
	ISNULL(ExecDepartmentId,0) as ExecDepartmentId,
	ISNULL((Select Top 1 DName From Department Where Id=p.ExecDepartmentId),'...') As ExecDepartment,
	ExecPerson,MoveCompanyId,
	ISNULL((Select Top 1 EName From Employee Where UserName=p.ExecPerson),'...') As ExecPersonName
	,IsNull((select product.flag from product where product.id=p.productid),0) flag
From Project p Where ProjectId=@ProjectId
